{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "initial_id",
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "/Users/younger/Library/Containers/com.tencent.xinWeChat/Data/Library/Application\\ Support/com.tencent.xinWeChat/2.0b4.0.9/a1af9de00751635dea3a72c040b295c5/Message/MessageTemp/f348131d27e877802ac98d7d5be97664/File/表数据信息.csv\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "dc7a71a681f68fbe",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-27T06:06:58.507444Z",
     "start_time": "2025-05-27T06:06:56.371980Z"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "146eda7cd427d802",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-27T06:10:04.281801Z",
     "start_time": "2025-05-27T06:10:04.279264Z"
    }
   },
   "outputs": [],
   "source": [
    "input_path = r\"../data/表数据信息.csv\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "73a2d99d9f8edb7e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-27T06:10:04.768284Z",
     "start_time": "2025-05-27T06:10:04.714521Z"
    }
   },
   "outputs": [],
   "source": [
    "df = pd.read_csv(input_path, encoding=\"gbk\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "76656c77515bf9c7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-27T06:10:09.459082Z",
     "start_time": "2025-05-27T06:10:09.450302Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>list_1</th>\n",
       "      <th>list_2</th>\n",
       "      <th>list_3</th>\n",
       "      <th>list_4</th>\n",
       "      <th>list_5</th>\n",
       "      <th>list_6</th>\n",
       "      <th>list_7</th>\n",
       "      <th>list_8</th>\n",
       "      <th>list_9</th>\n",
       "      <th>list_10</th>\n",
       "      <th>list_11</th>\n",
       "      <th>list_12</th>\n",
       "      <th>list_13</th>\n",
       "      <th>table_name</th>\n",
       "      <th>column_name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>杭州市</td>\n",
       "      <td>萧山机场</td>\n",
       "      <td>出港</td>\n",
       "      <td>商旅人员</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.928571</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>temp_lzy_xs_airport_result01_2024q3</td>\n",
       "      <td>o_city_name*o_county_name*d_city_name*d_county...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>杭州市</td>\n",
       "      <td>萧山机场</td>\n",
       "      <td>出港</td>\n",
       "      <td>商旅人员</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>temp_lzy_xs_airport_result01_2024q3</td>\n",
       "      <td>o_city_name*o_county_name*d_city_name*d_county...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>杭州市</td>\n",
       "      <td>萧山机场</td>\n",
       "      <td>出港</td>\n",
       "      <td>常住人口</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>temp_lzy_xs_airport_result01_2024q3</td>\n",
       "      <td>o_city_name*o_county_name*d_city_name*d_county...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  list_1 list_2 list_3 list_4 list_5 list_6  list_7    list_8  list_9  \\\n",
       "0    -99    -99    杭州市   萧山机场     出港   商旅人员     0.0  1.928571     NaN   \n",
       "1    -99    -99    杭州市   萧山机场     出港   商旅人员     1.0  2.000000     NaN   \n",
       "2    -99    -99    杭州市   萧山机场     出港   常住人口     0.0  1.000000     NaN   \n",
       "\n",
       "   list_10  list_11  list_12  list_13                           table_name  \\\n",
       "0      NaN      NaN      NaN      NaN  temp_lzy_xs_airport_result01_2024q3   \n",
       "1      NaN      NaN      NaN      NaN  temp_lzy_xs_airport_result01_2024q3   \n",
       "2      NaN      NaN      NaN      NaN  temp_lzy_xs_airport_result01_2024q3   \n",
       "\n",
       "                                         column_name  \n",
       "0  o_city_name*o_county_name*d_city_name*d_county...  \n",
       "1  o_city_name*o_county_name*d_city_name*d_county...  \n",
       "2  o_city_name*o_county_name*d_city_name*d_county...  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "d5291b49350df4e4",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-27T06:17:14.365799Z",
     "start_time": "2025-05-27T06:17:14.353060Z"
    }
   },
   "outputs": [],
   "source": [
    "df2 = df[[\"table_name\", \"column_name\"]].drop_duplicates().reset_index(drop=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "246372934e9b307a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-27T06:18:17.211270Z",
     "start_time": "2025-05-27T06:18:17.208210Z"
    }
   },
   "outputs": [],
   "source": [
    "df2_1 = df2.dropna()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "c9a6fbacaf7a50d3",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-27T06:18:20.709625Z",
     "start_time": "2025-05-27T06:18:20.703501Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>table_name</th>\n",
       "      <th>column_name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>temp_lzy_xs_airport_result01_2024q3</td>\n",
       "      <td>o_city_name*o_county_name*d_city_name*d_county...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>temp_lzy_xs_airport_stay01_2024q4</td>\n",
       "      <td>p_day*user_flag*avg_stay_time_h</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>temp_lzy_xs_airport_result02_2024q3</td>\n",
       "      <td>o_flag*d_flag*avg_cnt_per_day</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>temp_lzy_xs_airport_tourist_attr02_2024q4</td>\n",
       "      <td>p_day*p_index*p_index_desc*p_dir*user_flag*cnt</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>temp_lzy_xs_airport_stay02_2024q4</td>\n",
       "      <td>p_day*user_flag*stay_time_h*cnt</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>temp_lzy_chujing_destination_2024q4</td>\n",
       "      <td>arrive_prov*cnt_arrive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>temp_lzy_anjian_time_before_check_pdf_2024q3</td>\n",
       "      <td>time_before_check*num_passengers*ratio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>temp_lzy_chujing_airport_2024q3</td>\n",
       "      <td>leave_city*cnt_out</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>temp_xs_result_subway_time_count_1010</td>\n",
       "      <td>station_name_down*hour*total_count*count_0_to_...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>temp_lzy_anjian_time_before_check_pdf_2024q4</td>\n",
       "      <td>time_before_check*num_passengers*ratio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>temp_lzy_xs_airport_result07_2024q4</td>\n",
       "      <td>p_day*cert_code_prefix*cnt</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>temp_lzy_xs_airport_result04_2024q3</td>\n",
       "      <td>p_dir*user_flag*o_city_name*o_county_name*d_ci...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>temp_xs_result_subway_time_count_0816</td>\n",
       "      <td>station_name_down*hour*total_count*count_0_to_...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>temp_xs_result_subway_time_count_1016</td>\n",
       "      <td>station_name_down*hour*total_count*count_0_to_...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>temp_lzy_xs_airport_security_flow_by_time_2024q4</td>\n",
       "      <td>time_window*num_passengers*ratio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>temp_lzy_xs_airport_tourist_attr02_2024q3</td>\n",
       "      <td>p_day*p_index*p_index_desc*p_dir*user_flag*cnt</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>temp_lzy_xs_airport_result05_2024q3</td>\n",
       "      <td>p_day*time_window*window_start_time*num_passen...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>temp_lzy_xs_airport_stay02_2024q3</td>\n",
       "      <td>p_day*user_flag*stay_time_h*cnt</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>temp_lzy_xs_airport_result06_2024q3</td>\n",
       "      <td>p_day*time_window*window_start_time*num_passen...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>temp_lzy_xs_airport_result05_2024q4</td>\n",
       "      <td>p_day*time_window*window_start_time*num_passen...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>temp_lzy_chujing_airport_2024q4</td>\n",
       "      <td>leave_city*cnt_out</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>temp_lzy_xs_airport_result02_2024q4</td>\n",
       "      <td>o_flag*d_flag*avg_cnt_per_day</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>temp_lzy_xs_airport_result01_2024q4</td>\n",
       "      <td>o_city_name*o_county_name*d_city_name*d_county...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>temp_lzy_xs_airport_result04_2024q4</td>\n",
       "      <td>p_dir*user_flag*o_city_name*o_county_name*d_ci...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>temp_lzy_xs_airport_result03_2024q4</td>\n",
       "      <td>o_flag*d_flag*avg_cnt_per_day</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>temp_xs_result_subway_time_count_1028</td>\n",
       "      <td>station_name_down*hour*total_count*count_0_to_...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>temp_xs_result_subway_time_count_0807</td>\n",
       "      <td>station_name_down*hour*total_count*count_0_to_...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>temp_lzy_xs_airport_result03_2024q3</td>\n",
       "      <td>o_flag*d_flag*avg_cnt_per_day</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>temp_lzy_xs_airport_security_flow_by_time_2024q3</td>\n",
       "      <td>time_window*num_passengers*ratio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>temp_lzy_anjian_time_after_check_pdf_2024q3</td>\n",
       "      <td>time_after_check*num_passengers*ratio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>temp_lzy_anjian_time_after_check_pdf_2024q4</td>\n",
       "      <td>time_after_check*num_passengers*ratio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>temp_lzy_chujing_destination_2024q3</td>\n",
       "      <td>arrive_prov*cnt_arrive</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>temp_lzy_xs_airport_result06_2024q4</td>\n",
       "      <td>p_day*time_window*window_start_time*num_passen...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>temp_lzy_xs_airport_stay01_2024q3</td>\n",
       "      <td>p_day*user_flag*avg_stay_time_h</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>temp_xs_result_subway_time_count_1022</td>\n",
       "      <td>station_name_down*hour*total_count*count_0_to_...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>temp_xs_result_subway_time_count_0813</td>\n",
       "      <td>station_name_down*hour*total_count*count_0_to_...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                          table_name  \\\n",
       "0                temp_lzy_xs_airport_result01_2024q3   \n",
       "1                  temp_lzy_xs_airport_stay01_2024q4   \n",
       "2                temp_lzy_xs_airport_result02_2024q3   \n",
       "3          temp_lzy_xs_airport_tourist_attr02_2024q4   \n",
       "4                  temp_lzy_xs_airport_stay02_2024q4   \n",
       "5                temp_lzy_chujing_destination_2024q4   \n",
       "7       temp_lzy_anjian_time_before_check_pdf_2024q3   \n",
       "8                    temp_lzy_chujing_airport_2024q3   \n",
       "9              temp_xs_result_subway_time_count_1010   \n",
       "10      temp_lzy_anjian_time_before_check_pdf_2024q4   \n",
       "11               temp_lzy_xs_airport_result07_2024q4   \n",
       "12               temp_lzy_xs_airport_result04_2024q3   \n",
       "13             temp_xs_result_subway_time_count_0816   \n",
       "14             temp_xs_result_subway_time_count_1016   \n",
       "15  temp_lzy_xs_airport_security_flow_by_time_2024q4   \n",
       "16         temp_lzy_xs_airport_tourist_attr02_2024q3   \n",
       "17               temp_lzy_xs_airport_result05_2024q3   \n",
       "18                 temp_lzy_xs_airport_stay02_2024q3   \n",
       "19               temp_lzy_xs_airport_result06_2024q3   \n",
       "20               temp_lzy_xs_airport_result05_2024q4   \n",
       "21                   temp_lzy_chujing_airport_2024q4   \n",
       "22               temp_lzy_xs_airport_result02_2024q4   \n",
       "23               temp_lzy_xs_airport_result01_2024q4   \n",
       "24               temp_lzy_xs_airport_result04_2024q4   \n",
       "25               temp_lzy_xs_airport_result03_2024q4   \n",
       "26             temp_xs_result_subway_time_count_1028   \n",
       "27             temp_xs_result_subway_time_count_0807   \n",
       "28               temp_lzy_xs_airport_result03_2024q3   \n",
       "29  temp_lzy_xs_airport_security_flow_by_time_2024q3   \n",
       "30       temp_lzy_anjian_time_after_check_pdf_2024q3   \n",
       "31       temp_lzy_anjian_time_after_check_pdf_2024q4   \n",
       "32               temp_lzy_chujing_destination_2024q3   \n",
       "33               temp_lzy_xs_airport_result06_2024q4   \n",
       "34                 temp_lzy_xs_airport_stay01_2024q3   \n",
       "35             temp_xs_result_subway_time_count_1022   \n",
       "36             temp_xs_result_subway_time_count_0813   \n",
       "\n",
       "                                          column_name  \n",
       "0   o_city_name*o_county_name*d_city_name*d_county...  \n",
       "1                     p_day*user_flag*avg_stay_time_h  \n",
       "2                       o_flag*d_flag*avg_cnt_per_day  \n",
       "3      p_day*p_index*p_index_desc*p_dir*user_flag*cnt  \n",
       "4                     p_day*user_flag*stay_time_h*cnt  \n",
       "5                              arrive_prov*cnt_arrive  \n",
       "7              time_before_check*num_passengers*ratio  \n",
       "8                                  leave_city*cnt_out  \n",
       "9   station_name_down*hour*total_count*count_0_to_...  \n",
       "10             time_before_check*num_passengers*ratio  \n",
       "11                         p_day*cert_code_prefix*cnt  \n",
       "12  p_dir*user_flag*o_city_name*o_county_name*d_ci...  \n",
       "13  station_name_down*hour*total_count*count_0_to_...  \n",
       "14  station_name_down*hour*total_count*count_0_to_...  \n",
       "15                   time_window*num_passengers*ratio  \n",
       "16     p_day*p_index*p_index_desc*p_dir*user_flag*cnt  \n",
       "17  p_day*time_window*window_start_time*num_passen...  \n",
       "18                    p_day*user_flag*stay_time_h*cnt  \n",
       "19  p_day*time_window*window_start_time*num_passen...  \n",
       "20  p_day*time_window*window_start_time*num_passen...  \n",
       "21                                 leave_city*cnt_out  \n",
       "22                      o_flag*d_flag*avg_cnt_per_day  \n",
       "23  o_city_name*o_county_name*d_city_name*d_county...  \n",
       "24  p_dir*user_flag*o_city_name*o_county_name*d_ci...  \n",
       "25                      o_flag*d_flag*avg_cnt_per_day  \n",
       "26  station_name_down*hour*total_count*count_0_to_...  \n",
       "27  station_name_down*hour*total_count*count_0_to_...  \n",
       "28                      o_flag*d_flag*avg_cnt_per_day  \n",
       "29                   time_window*num_passengers*ratio  \n",
       "30              time_after_check*num_passengers*ratio  \n",
       "31              time_after_check*num_passengers*ratio  \n",
       "32                             arrive_prov*cnt_arrive  \n",
       "33  p_day*time_window*window_start_time*num_passen...  \n",
       "34                    p_day*user_flag*avg_stay_time_h  \n",
       "35  station_name_down*hour*total_count*count_0_to_...  \n",
       "36  station_name_down*hour*total_count*count_0_to_...  "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2_1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "214ad3722920daa5",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-27T06:30:40.220124Z",
     "start_time": "2025-05-27T06:30:40.214628Z"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import os\n",
    "\n",
    "def split_table_data_by_table_name(input_csv_path, output_dir):\n",
    "    # 读取 CSV 文件，尝试兼容常用编码\n",
    "    df = pd.read_csv(input_csv_path, encoding=\"gbk\")\n",
    "    if 'table_name' not in df.columns or 'column_name' not in df.columns:\n",
    "        df = pd.read_csv(input_csv_path, encoding='gb18030')\n",
    "\n",
    "    # 删除 table_name 和 column_name 为空的行\n",
    "    df_filtered = df.dropna(subset=[\"table_name\", \"column_name\"])\n",
    "\n",
    "    # 提取 list_1 到 list_13 列名\n",
    "    list_cols = [col for col in df.columns if col.startswith(\"list_\")]\n",
    "\n",
    "    # 创建输出目录（如果不存在）\n",
    "    os.makedirs(output_dir, exist_ok=True)\n",
    "\n",
    "    # 按照 table_name 分组\n",
    "    for table_name, group in df_filtered.groupby(\"table_name\"):\n",
    "        # 获取每行的列数（通过 column_name 拆分）\n",
    "        col_counts = group[\"column_name\"].str.count(r'\\*') + 1\n",
    "\n",
    "        # 提取每行前 n 个非空值\n",
    "        extracted_rows = []\n",
    "        for i, row in group.iterrows():\n",
    "            n = col_counts.loc[i]\n",
    "            values = [row[col] for col in list_cols if pd.notnull(row[col])][:n]\n",
    "            extracted_rows.append(values)\n",
    "\n",
    "        # 获取列名\n",
    "        column_names = group[\"column_name\"].iloc[0].split(\"*\")\n",
    "        table_df = pd.DataFrame(extracted_rows, columns=column_names)\n",
    "\n",
    "        # 保存为 CSV 文件\n",
    "        output_path = os.path.join(output_dir, f\"{table_name}.csv\")\n",
    "        table_df.to_csv(output_path, index=False, encoding=\"gbk\")\n",
    "\n",
    "# 示例用法（替换为你的路径）：\n",
    "# split_table_data_by_table_name(\"表数据信息.csv\", \"./output_tables\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "2c79eff97fb5d50a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-27T06:30:41.913043Z",
     "start_time": "2025-05-27T06:30:40.747335Z"
    }
   },
   "outputs": [],
   "source": [
    "split_table_data_by_table_name(\"../data/表数据信息.csv\", \"../data/output-0527\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1fefba7a900cd700",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
